/**
 * Chargement de l'arbre affichant les segments.
 */
function loadTreeSegments() {
	var segments = new Array();
	
	var cible = new Object();
	cible.attr = new Object();
	cible.attr.id = "CIBLE";
	cible.attr.selected = true;
	cible.data = new Object();
	cible.data.title = "Cible";
	cible.children = new Array();
	
	var a = new Object();
	a.attr = new Object();
	a.attr.id = "A";
	a.attr.selected = true;
	a.data = new Object();
	a.data.title = "A";
	
	var b = new Object();
	b.attr = new Object();
	b.attr.id = "B";
	b.attr.selected = true;
	b.data = new Object();
	b.data.title = "B";
	
	var c = new Object();
	c.attr = new Object();
	c.attr.id = "C";
	c.attr.selected = true;
	c.data = new Object();
	c.data.title = "C";
	
	var d = new Object();
	d.attr = new Object();
	d.attr.id = "D";
	d.attr.selected = true;
	d.data = new Object();
	d.data.title = "D";
	
	cible.children[0] = a;
	cible.children[1] = b;
	cible.children[2] = c;
	cible.children[3] = d;
	
	var hc = new Object();
	hc.attr = new Object();
	hc.attr.id = "HC";
	hc.attr.selected = true;
	hc.data = new Object();
	hc.data.title = "HC";
	
	segments[0] = cible;
	segments[1] = hc;
	
	$("#treeSegments").jstree({
		plugins: ["themes", "json_data", "crrm", "ui", "unique", "types", "search", "checkbox"],
		json_data : { 
			data: segments
 		} 
	}).bind("change_state.jstree", function (e, data) {
		// Lorsqu'une checkbox est cochée ou décochée 
		var checked_ids = "";
		// On recupere tous les ID des produits cochés 
	    $('#treeSegments').jstree("get_checked", null, true).each(function() {
	    	if (this.id != 'CIBLE') {
	    		checked_ids += this.id + "+";
	    	}
	    });	
	    if (checked_ids != "") {
	    	checked_ids = checked_ids.substring(0, checked_ids.length-1);
	    }
	    // On change la variable globale
	    allSegments = checked_ids;
	    // Rafraichissement 
	    refreshCharts();
	    // Rafraichissement de la zone sud 
		var southZone = Ext.getCmp('southZone');
		if (!southZone.hidden) {
			// Top UGPN ou liste des medecins
//			var grid2 = Ext.getCmp('grid2');
//			if (!grid2.hidden) {
//				$("#grid").html('<img src="img/ajax-loader.gif" style="padding-right:5px;" />');
//				if (!ugp) {
//					loadGridUGA(globalCodeUGP);
//				} else {
//					loadGrid(globalCodeUGP);
//				}
//			}
			// Liste des medecins 
			var grid3 = Ext.getCmp('grid3');
			if (!grid3.hidden) {
				$("#gridDoctors").html('<img src="img/ajax-loader.gif" style="padding-right:5px;" />');
				loadGridDoctors();
			}
		} 
	    // Mise à jour de la partie informations 
	    $('#infoSegment').html(allSegments);
	}).bind("loaded.jstree", function (event, data) {
		$('#treeSegments').jstree('check_node', '#CIBLE');
	}); 
}